home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / Q-R / Q&A.PAS next >
Pascal/Delphi Source File  |  1987-06-30  |  9KB  |  246 lines

  1.             TURBO PASCAL FOR THE MACINTOSH
  2.              Common Questions and Answers:
  3.  
  4. Q: Do I need Turbo to run programs I developed using Turbo? 
  5.  
  6. A: No, you can create a "stand-alone" (double-clickable)
  7. application  by  selecting  the  Compile  To  Disk  item from the
  8. Compile menu. 
  9.  
  10.  
  11. Q:What are the code and data limits for a Turbo Pascal program?
  12.  
  13. A:The Macintosh limits the code size of a program to 32K bytes. 
  14. You can overcome this limitation by segmenting your program. 
  15. This means you can have several 32K segments and you are the size
  16. of your program is only by disk space.  For more information on
  17. segmenting see the Large Programs and Segmentation in chapter 9
  18. and the Units and Large Programs section in chapter 8.
  19.  
  20. The Macintosh limits a program to 32K bytes of global data.  To
  21. overcome this limitation you can use pointers as in the following
  22. sample: 
  23. program SaveSpace;
  24. type
  25.   BigArray = array[1..$8000] of integer;
  26.    { if we declared a variable of this type it would occupy 16K }
  27.                      {  bytes.  Half of our global data space!! }
  28. var
  29.   SpaceSaver : ^BigArray;
  30.   i : integer;
  31. begin
  32.   New(SpaceSaver);   { allocate space for array off of the heap }
  33.   for i := to $8000 do
  34.     SpaceSaver^[i] := i; { index element by derefencing pointer }
  35. end.
  36.  
  37.  
  38. Q: How to a raise a number to a power?
  39.  
  40. A: Include the following function in your program:
  41.  
  42.   function Raise(x, y : real) : real;
  43.   begin
  44.     Raise := exp(y * ln(x));
  45.   end; { Raise }
  46.  
  47.  
  48. Q: How do I take the log base 10 of a number?
  49.  
  50. A: Include the following function in your program:
  51.    function Log(r : real) : real;
  52.    begin
  53.      Log := ln(r) / ln(10);
  54.    end;  
  55.  
  56.  
  57. Q: I am trying to call one of the Macintosh Toolbox routines
  58. which takes a parameter of type PTR and I get a compiler error 44
  59. (type mismatch) when I pass it a StringPtr.  How can I get this
  60. to compile?
  61.  
  62. A: Because of Pascal's strong typing rules, you can't directly
  63. assign a value of type PTR for example to some other pointer
  64. type.  Instead, you have to coerce the pointer from one type to
  65. another with variable type casts.  For an example please refer to
  66. the Variable-Type-Casts section at the end of chapter 19 in the
  67. Turbo Refernce manual.
  68.  
  69.  
  70. Q: I am writing a program that uses a "Macintosh Interface" but
  71. when the program starts up a window flashes up on the screen and
  72. then disappears.  How do I get rid of this window altogether?
  73.  
  74. A: You are seeing is Turbo's PasConsole window which makes it
  75. easy to set up text book programs.  To eliminate PasConsole set
  76. the {$U-} directive after your program statement.
  77.  
  78. Warning: Pasconsole initialize various Toolbox managers for you
  79. so if you set {$U-} you must explicitily initialize these
  80. managers.  Please refer to the Initialization section in chapter
  81. 9 of the Turbo Pascal Reference Manual.
  82.  
  83.  
  84. Q: I am trying to write a program using QuickDraw but its not
  85. working.  Nothing seems to be getting initialized as the
  86. documentation in Inside Macintosh indicates.  What is going
  87. wrong?
  88.  
  89. A: If your program does not have the {$U-} directive, the
  90. PasConsole unit will automatically used in your program. 
  91. Pasconsole defines and initializes its own set of QuickDraw
  92. global variables to support the console window.
  93.  
  94. If your program uses both Pasconsole and QuickDraw, the QuickDraw
  95. Unit's own set of global variables need to be initialized by
  96. making the call InitGraf(@thePort).  Before doing this however
  97. you need to save the pointer to the PasConsole window or its
  98. value will be wiped out InitGraf call as illustrated below. 
  99. Include the following procedure in your program and call it once
  100. at the very beginning of your program. 
  101.  
  102. procedure SetUpQuickDraw;
  103. var
  104.   TurboPort : GrafPtr;
  105. begin
  106.   GetPort(TurboPort);  { Save the PasConsole window pointer }
  107.   InitGraf(@thePort);
  108.   SetPort(TurboPort); { Restore the PasConsole window pointer }
  109. end;
  110.  
  111.  
  112. Q: How do I generate random numbers with Turbo for the Mac?  I
  113. tried using QuickDraw's random number generator but I each time 
  114. the program runs it generates the same sequence of numbers even
  115. though I change the value of RandSeed (the seed value used by the
  116. genearator).  What am I doing wrong?
  117.  
  118. A: RandSeed is a QuickDraw global variable so you need to
  119. initialize this variable with the SetUpQuickDraw procedure listed
  120. above.  Below is a sample program that uses the system clock to
  121. ensure that the program generates a different sequence of numbers
  122. each time:
  123.  
  124. program RandomTest;
  125. uses MemTypes, QuickDraw, OSIntf, ToolIntf;
  126.  
  127. var 
  128.   i : integer;
  129. begin
  130.   SetUpQuickDraw; { use the procedure listed above }
  131.   RandSeed := TickCount; { Set the seed to the time }
  132.   for i := 1 to 20 do
  133.     Writeln(abs(Random) mod i);
  134.   Readln;
  135. end.
  136.  
  137.  
  138. Q: How do I output text from my program to the printer?
  139. A: You must include the PasPrinter unit and Write to the Printer
  140. logical device as shown below:
  141.  
  142. program PrintTest;
  143. uses PasPrinter;
  144.  
  145. begin
  146.   Writeln(Printer, 'Send this to the printer');
  147.   Close(Printer);
  148. end.
  149.  
  150. Note: On LaserWriter printers you MUST close the Printer logical
  151. device to get output.
  152.  
  153.  
  154. Q: How do I do a screen dump to the printer?  I want to print out
  155. QuickDraw graphics as well as Turbo's Turtle graphics?
  156.  
  157. A: The following program demonstrates the Macintosh calls to
  158. print the top folder on the screen and/or the whole screen:
  159.  
  160. program ScreenDump;
  161. uses MemTypes, QuickDraw, OSIntf, ToolIntf, MacPrint;
  162.  
  163. procedure HardCopy(TopWindowOnly : boolean);
  164. begin
  165.   PrDrvOpen;
  166.   if TopWindowOnly then 
  167.     PrtCall(iPrEvtCtl, LprEvtTop, 0, LScreenBits)
  168.   else
  169.     PrtCall(iPrEvtCtl, LprEvtAll, 0, LScreenBits);
  170.   PrDrvrClose;
  171. end; { HardCopy }
  172.  
  173. begin
  174.   HardCopy(true);  { print Turbo's PasConsole window }
  175. end.
  176.  
  177.  
  178. Q: How do I find get more documentation on the procedures and
  179. functions listed in the Macintosh Interfaces Units listed in
  180. Appendix D of the Turbo Pascal Reference Manual?
  181.  
  182. A: Apple Computer's official documentation, INSIDE MACINTOSH, is
  183. the most complete documentation on the Macintosh and its
  184. Toolboxes.
  185.  
  186.  
  187. Q: The Turbo Reference Manual it indicates you can shift text
  188. left and right using the (clover)[ and (clover)] keys.  I was
  189. unable to shit the text in my program.  Also these commands are
  190. not highlighted on the Edit menu.  What is wrong?
  191.  
  192. A: The text you highlight to be shifted must be made up of
  193. complete lines of text.  To mark a complete line move the mouse
  194. to the leftmost column on the screen and select the text using
  195. the click and drag method moving straight down the left side. 
  196. You should see the lines highlighted all the way across the
  197. screen.  You can then shift the (rectangular) block.
  198.  
  199.  
  200. Q: Is there any way to stop a Turbo program short of hitting the
  201. Reset button and restarting the machine which is very time consuming?
  202.  
  203. A: The following procedure sets up your system to allow you to
  204. break out of a Turbo Pascal program without rebooting.  On the
  205. SAMPLES AND UTILITIES diskette in the MISCELLANEOUS folder there
  206. is a file calles MACSBUG.  If you put this file in your System
  207. Folder and restart your system, the MACSBUG debugger will
  208. automatically be loaded into memory.  Now, whenever you need to
  209. break out of a Turbo program press the interrupt switch (the
  210. switch behind the reset switch on the left side of your
  211. Macintosh, assuming you have installed the switches).  This will
  212. put you in the MacsBug debugger and you will see a ">" prompt. 
  213. At this prompt type ES and you will be returned to the Turbo
  214. Environment.
  215.  
  216.  
  217. Q: When I run my Turbo program it bombs bringing up a Macintosh
  218. bomb box with Error 2.  After hitting the Resume Error it goes
  219. into the Turbo brings up an error message saying TARGET ADDRESS
  220. FOUND IN UNIT placing the cursor at the end of my source file. 
  221. What is happening?
  222.  
  223. A: A system error 2 is an addressing error because some Macintosh
  224. Toolbox routine is being passed an invalid pointer or handle. 
  225. Since the error is happening in one of these pre-compiled units
  226. Turbo cannot take to the source line of the error.  Make sure
  227. that your program checks all error codes returned from Toolbox
  228. routines and make sure no errors have occurred before proceeding. 
  229. Also refer to the chapter DEBUGGING YOUR TURBO PASCAL PROGRAM in
  230. the Turbo Pascal Reference Manual.
  231.  
  232.  
  233. Q: I am trying to port over some Turbo Pascal programs from the
  234. IBM PC to Turbo Pascal for the Macintosh and I am getting
  235. compiler errors.  Why isn't Turbo for the Mac fully compatible?
  236.  
  237. A: Serious Pascal developers on the Macintosh have adopted the
  238. Lisa Pascal standard.  So it was necessary that Turbo Pascal
  239. follows these standards.  We have tried to also maintain close
  240. compatibility with other implementations of Turbo Pascal.  When
  241. these standards conflict it was necessary that we adopt the Lisa
  242. Pascal standard.  For closer compatibility with the IBM PC
  243. version of Turbo Pascal we have implemented a compatibility unit
  244. that you can include in your programs.  This unit is in a file
  245. called Compat.inc in data library 5 of the Borland Programmers
  246. Forum.